home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / bigint.arc / BIGINT.H < prev   
Encoding:
C/C++ Source or Header  |  1986-04-20  |  1.3 KB  |  53 lines

  1. /*
  2.  * Defines the basic structure of a big integer
  3.  * and gives basic macro definitions.
  4.  *
  5.  *            R. G. Larson
  6.  *            25 June 1985
  7.  */
  8.  
  9. #define DUMMY_LEN 2    /* dummy number size */
  10.  
  11. typedef unsigned short BIDIG;
  12. typedef short           sBIDIG;
  13.  
  14. #define BIBASE       65536   /* number base */
  15.  
  16. #define dBIBASE    65536.0 /* number base as double */
  17.  
  18. typedef struct bigint    {
  19.     int   _bimax;    /* number of words alloc for integer */
  20.     int   _bilen;    /* number of words currently used */
  21.     BIDIG _binum[DUMMY_LEN];
  22. } BIGINT, *BIGINTP;
  23.  
  24. #define bisize(P)  ((P) -> _bilen)
  25.  
  26. #define bilt0(n)   (((sBIDIG) (n -> _binum[n -> _bilen - 1])) < 0)
  27.  
  28. #define bieq0(n)   ((n -> _bilen == 1) && (n -> _binum[0] == 0))
  29.  
  30. #define bige0(n)   (((sBIDIG) (n -> _binum[n -> _bilen - 1])) >= 0)
  31.  
  32. #define bile0(n)   (bilt0(n) || bieq0(n))
  33.  
  34. #define bigt0(n)   (bige0(n) && !bieq0(n))
  35.  
  36. #define bine0(n)   (!bieq0(n))
  37.  
  38. #define bigt(P,Q)  (bilt(Q,P))
  39.  
  40. #define bige(P,Q)  (!bilt(P,Q))
  41.  
  42. #define bile(P,Q)  (!bilt(Q,P))
  43.  
  44. #define bine(P,Q)  (!bieq(P,Q))
  45.  
  46. #define bisize(P)  (P -> _bimax)
  47.  
  48. #define biodd(P)   ((bool) ((P -> _binum[0]) & ((BIDIG) 1)))
  49.  
  50. #define bieven(P)  (!biodd(P))
  51.  
  52. #define biabs(Q,P) (bilt0(P) ? bineg(Q,P) : bicopy(Q,P))
  53.